/**
 * React Starter Kit (https://www.reactstarterkit.com/)
 *
 * Copyright © 2014-present Kriasoft, LLC. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.txt file in the root directory of this source tree.
 */

import React from 'react';
import PropTypes from 'prop-types';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import s from './Home.css';
import fetch from '../../core/fetch/fetch.server.js';
import Chart from '../../components/Chart/Chart.js';

class Home extends React.Component {
  static propTypes = {
    news: PropTypes.arrayOf(PropTypes.shape({
      title: PropTypes.string.isRequired,
      link: PropTypes.string.isRequired,
      content: PropTypes.string,
    })).isRequired,
  };

  constructor(props) {
    super(props)
    this.state = {
      units: [],
    }
    fetch('https://nortech01:NorTech01@ehp-data.com/api/v2/dataloggers/20201/units/')
      .then(res => res.json())
      .then(res => {
        console.log(res.results)
        this.setState({ units: res.results })
      });

  }


  render() {
    return (
      <div className={s.root}>
        <div className={s.container}>
          <h1>Datalogger</h1>
          {
              this.state.units ?
              this.state.units.map((unit,i) => (
                <Chart key={i} unit={unit}>
                </Chart>
              )) : null
            }
            <Chart></Chart>
        </div>
      </div>
    );
  }
}

export default withStyles(s)(Home);
